package com.atfcm.hash;

public class T_202_快乐数 {
    public int sq(int n){
        int res = 0;
        while(n > 0){
            int i = n % 10;
            res = res +  i * i;
            n = n/10;
        }
        return res;
    }

    public boolean isHappy(int n) {
        int slow = n,fast = sq(n);
        while(slow != fast){
            slow = sq(slow);
            fast = sq(sq(fast));
        }
        return slow == 1;
    }



}
